package com.lizhenhua.fmmall.config;

import com.lizhenhua.fmmall.interceptor.CheckTokenInterceptor;
import com.lizhenhua.fmmall.interceptor.SetTimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //配置类注解   实现WebMvcConfigurer 配置接口
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private CheckTokenInterceptor checkTokenInterceptor;
    @Autowired
    private SetTimeInterceptor setTimeInterceptor;

    // 新增一个拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkTokenInterceptor)
                .addPathPatterns("/shopcart/**")
                .addPathPatterns("/order/**")
                .addPathPatterns("/userAddr/**")
                .addPathPatterns("/user/userTokenCheck")
//                .addPathPatterns("/**") //拦截所有
                .excludePathPatterns("/user/**"); // 除了/user 开头的
//                .excludePathPatterns("/doc.html")
//                .excludePathPatterns("/swagger-ui/**")
//                .excludePathPatterns("/swagger2/**");

        registry.addInterceptor(setTimeInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login");
    }
}
